package com.swanclouds.redfish.chassis;

import com.google.common.base.Preconditions;
import com.swanclouds.api.chassis.NetworkAdaptersService;
import com.swanclouds.core.transport.ClientConstants;
import com.swanclouds.model.common.redfish.CollectionResource;
import com.swanclouds.redfish.chassis.domain.NetworkAdaptersModel;
import com.swanclouds.redfish.common.redfish.CollectionResourceModel;
import com.swanclouds.redfish.internal.BaseChassisService;

import java.util.ArrayList;
import java.util.List;

/**
 * Author: HuangFuYuHui
 * Title: NetworkAdaptersServiceImpl
 * Description: TODO
 * Date: 2022/7/18 15:33
 */
public class NetworkAdaptersServiceImpl extends BaseChassisService implements NetworkAdaptersService {

    /**
     * 查询网卡集合资源信息
     * @return CollectionResource
     **/
    @Override
    public CollectionResource get() {
        return get(CollectionResourceModel.class,uri(ClientConstants.PATH_CHASSIS_NETWORKADAPTERS,getChassisId())).execute();
    }

    /**
     * 查询指定网络适配器集合资源信息
     * @param networkAdapterId 网络适配器Id
     * @return NetworkAdapters
     **/
    @Override
    public NetworkAdaptersModel getNetworkAdapter(String networkAdapterId) {
        Preconditions.checkNotNull(networkAdapterId, "networkAdapterId is null");
        return get(NetworkAdaptersModel.class,uri(ClientConstants.PATH_CHASSIS_NETWORKADAPTERS_ID,getChassisId(),networkAdapterId)).execute();
    }

   /**
    * 查询网络适配器集合资源信息
    * @return java.util.List
    **/
    @Override
    public List<NetworkAdaptersModel> list() {
        List<NetworkAdaptersModel> networkAdaptersModel = new ArrayList<NetworkAdaptersModel>();
        CollectionResource collectionResource = get();
        collectionResource.getCollectionResourceList().stream().forEach(ref -> {
            NetworkAdaptersModel execute = get(NetworkAdaptersModel.class, uri(ref)).execute();
            networkAdaptersModel.add(execute);
        });
        return networkAdaptersModel;
    }

}
